<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        .box{
            width: 300px;
            margin: 150px auto;
        }
        .text{
            width: 100%;
            height: 50px;
            border: 1px solid black;
            display:flex;
            justify-content: center;
            align-items: center;
        }
        #passWord{
            width: 80%;
            height: 40px;
        }
        .progress{
            width: 100%;
            height: 50px;
            border: 1px solid black;
            margin-top: 5px;
            background-color: skyblue;
        }
        .inner{
            width: 0%;
            height: 50px;
            background-color: red;
        }
    </style>
</head>
<body>
    <div class="box">
        <div class="text">
            <input type="text" id="passWord">
        </div>
        <div class="progress">
            <div class="inner"></div>
        </div>
    </div>
</body>
<script>
    // 使用正则表达式判断密码输入强度
    // 获取元素 注册事件
    let passWord = document.getElementById('passWord');
    let inner = document.querySelector('.inner');
    passWord.oninput = function(){
        // console.log(123)
        // 获取到输入框的内容
        let text = passWord.value;
        let lv = 0;
        if(text.length >= 6){
            // console.log(123)
            if(/\w/.test(text)){
                lv++;
            }
            if(/[A-Za-z]/.test(text)){
                lv++;
            }
            if(/[*-+_]/.test(text)){
                lv++;
            }
            if(text.length >= 12){
                lv++; 
            } 
        }
        inner.style.width = lv * 25 + '%';  
    }
</script>
</html>